package com.runmi.webchat.aftersale.web.set.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.runmi.webchat.aftersale.common.result.Result;
import com.runmi.webchat.aftersale.web.base.BaseController;
import com.runmi.webchat.aftersale.web.set.model.RoleConfig;
import com.runmi.webchat.aftersale.web.set.model.RoleConfigSave;
import com.runmi.webchat.aftersale.web.set.model.RoleEdit;
import com.runmi.webchat.aftersale.web.set.model.RoleIndex;
import com.runmi.webchat.aftersale.web.set.model.RoleSeachlist;
import com.runmi.webchat.aftersale.web.set.service.RoleService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Controller
@RequestMapping(value = "/set/role")
public class RoleController  extends BaseController{

	@Autowired
	private RoleService roleService;
	
	
	@RequestMapping(value = "/index")
	public ModelAndView index(HttpServletRequest request,HttpServletResponse response,RoleIndex model){
		ModelAndView mav = new ModelAndView("/set/role/index");		
		roleService.index(model);
    	mav.addObject("model", model);
        return mav;
		//return "/customer/Customer/seach";
	}
	

	
	@ApiOperation(value = "角色-获取所有角色", notes = "获取所有角色", tags={ "系统设置", })
	@RequestMapping(value = "/getAllRoles")
	@ResponseBody
	public Result getAllJobs(){	
		return roleService.getAllRoles();
    	
		//return "/customer/Customer/seach";
	}
	
	
	@ApiOperation(value = "角色-根据角色ID查询角色信息", notes = "根据角色ID查询角色信息", tags={ "系统设置", })
	@RequestMapping(value = "/edit",produces = { "application/json" },method = RequestMethod.GET)
	public ModelAndView getRoleById(
			RoleEdit model){	
		ModelAndView mav = new ModelAndView("/set/role/edit");		
		roleService.edit(model);
    	mav.addObject("model",model);
        return mav;
    	
	}
	
	@ApiOperation(value = "角色-新增或者修改角色信息", notes = "新增或者修改角色信息", tags={ "系统设置", })
	@RequestMapping(value = "/saveRole",produces = { "application/json" },method = RequestMethod.POST)
	@ResponseBody
	public Map<String,String> saveRole(HttpServletRequest request, HttpServletResponse response,
			@ApiParam(value = "角色ID") @RequestParam(value = "roleId",required = false) Integer roleId,
			@ApiParam(value = "角色名称") @RequestParam(value = "roleName",required = false) String roleName,
			@ApiParam(value = "角色备注") @RequestParam(value = "remark",required = false) String remark
			){
		Map<String,String> result=roleService.saveRole(this.getUserInfo(request,response),roleId,roleName,remark);
		return result;
	}
	
	
	
	@ApiOperation(value = "角色-删除角色", notes = "删除角色", tags={ "系统设置", })
	@RequestMapping(value = "/delRole",produces = { "application/json" },method = RequestMethod.POST)
	@ResponseBody
	public Map<String,String> delRole(HttpServletRequest request, HttpServletResponse response,
			@ApiParam(value = "角色ID") @RequestParam(value = "roleId",required = true) Integer roleId){
	
		Map<String,String> result=roleService.delRole(this.getUserInfo(request,response),roleId);
		return result;
	}
	
	@ApiOperation(value = "角色-角色对应菜单", notes = "角色对应菜单", tags={ "系统设置", })
	@RequestMapping(value = "/config")
	public ModelAndView config(
			HttpServletRequest request,HttpServletResponse response,
			RoleConfig model){		
		//return roleService.config(this.getUserInfo(tocken),roleId);
		ModelAndView mav = new ModelAndView("/set/role/config");		
		roleService.config(this.getUserInfo(request, response),model);
    	mav.addObject("model",model);
        return mav;

	}
	
	@ApiOperation(value = "角色-角色菜单保存", notes = "角色菜单保存", tags={ "系统设置", })
	@RequestMapping(value = "/configSave",produces = { "application/json" },method = RequestMethod.POST)
	@ResponseBody
	public Map<String,String> configSave(HttpServletRequest request,HttpServletResponse response,RoleConfigSave model){
		Map<String,String> result=roleService.configSave(this.getUserInfo(request,response),model);
		return result;
	}

}
